package com.relytosoft.mizar.media.camera.services.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.relytosoft.mizar.media.camera.api.entity.CameraPlatform;
import com.relytosoft.mizar.media.camera.services.mapper.CameraPlatformMapper;
import com.relytosoft.mizar.media.camera.services.service.CameraPlatformService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lj
 */
@Service
public class CameraPlatformServiceImpl extends ServiceImpl<CameraPlatformMapper, CameraPlatform> implements CameraPlatformService {

    @Override
    public List<CameraPlatform> find(CameraPlatform cameraPlatform) {
        LambdaQueryWrapper<CameraPlatform> wrapper = Wrappers.lambdaQuery();
        wrapper
                .eq(cameraPlatform.getOwnId() != null, CameraPlatform::getOwnId, cameraPlatform.getOwnId())
                .eq(!StrUtil.isEmptyIfStr(cameraPlatform.getType()), CameraPlatform::getType, cameraPlatform.getType())
                .eq(cameraPlatform.getStatus() != null, CameraPlatform::getStatus, cameraPlatform.getStatus())
                .eq(!StrUtil.isEmptyIfStr(cameraPlatform.getPlatformName()), CameraPlatform::getPlatformName, cameraPlatform.getPlatformName())
                .eq(!StrUtil.isEmptyIfStr(cameraPlatform.getPlatformChannelCode()), CameraPlatform::getPlatformChannelCode, cameraPlatform.getPlatformChannelCode());
        return this.list(wrapper);
    }

    @Override
    public CameraPlatform findById(Integer id) {
        LambdaQueryWrapper<CameraPlatform> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CameraPlatform::getOwnId, id);
        wrapper.eq(CameraPlatform::getType, 2);
        return this.getOne(wrapper);
    }
}